package club.emergency.wechat.persistence.role;

import club.emergency.wechat.model.role.Role;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author jifujun
 * @since 2019-03-19
 */
public interface RoleMapper extends BaseMapper<Role> {

    /**
     * 根据id删除角色
     *
     * @param id 角色id
     */
    @Delete("delete from role where id = #{id}")
    void removeById(@Param("id") Long id);

    /**
     * 检查新增时角色是否唯一
     *
     * @param roleName 角色名称
     * @return 个数
     */
    @Select("select count(id) from role where role_name = #{roleName}")
    Integer checkOnlyForSave(@Param("roleName") String roleName);

    /**
     * 检查修改时角色名是否唯一
     *
     * @param roleName 角色名称
     * @param id       自身id
     * @return 个数
     */
    @Select("select count(id) from role where role_name = #{roleName} and id != #{id}")
    Integer checkOnlyForEdit(@Param("roleName") String roleName, @Param("id") Long id);
}
